const Task = require('./index');

/**
 * 任务
 */
class AnchorTask extends Task {

    /**
     *
     * @param page
     */
    async init(page) {
        await super.init(page);
        if (!this.__init)
            return {};
        let script = null;
        switch (this.hostname) {
            case 'panda.tv':
            case 'www.panda.tv':
                script = 'panda';
                break;
            case 'huomao.com':
            case 'www.huomao.com':
                script = 'huomao';
                break;
            case 'chushou.tv':
            case 'www.chushou.tv':
                script = 'chushou';
                break;
            case 'zhanqi.tv':
            case 'www.zhanqi.tv':
                script = 'zhanqi';
                break;
            case 'douyu.com':
            case 'www.douyu.com':
                script = 'douyu';
                break;
            case 'huya.com':
            case 'www.huya.com':
                script = 'huya';
                break;
            case 'live.bilibili.com':
                script = 'bilibili';
                break;
            case 'longzhu.com':
            case 'star.longzhu.com':
                script = 'longzhu';
                break;
            case 'y.longzhu.com':
                script = 'y.longzhu.js';
                break;
            case 'quanmin.tv':
            case 'www.quanmin.tv':
                script = 'quanmin';
                break;
            case 'yy.com':
            case 'www.yy.com':
                script = 'yy';
                break;
            case 'shihou.tv':
            case 'www.shihou.tv':
                script = 'shihou';
                break;
            case 'cc.163.com':
                script = 'cc.163.js';
                break;
            case 'egame.qq.com':
                script = 'egame.qq.com.js';
                break;
            case 'huajiao.com':
            case 'www.huajiao.com':
                script = 'huajiao.js';
                break;
            default:
                script = 'all.js';
        }
        // console.log({script});
        await require('./website/' + script)({page, sleep});
    }
}

module.exports = AnchorTask;

function sleep(time) {
    return new Promise(resolve => {
        setTimeout(resolve, time);
    });
}